
import '../main.dart';
import 'convert_util.dart';

String? analysisBookRule(String block){
  String rule = settingEntity.analysisBook??'xy';
  String? result = '';
  if(rule == 'xy'){
    result = xyRule(block);
  }
  if(rule == 'nt'){
    result = ntRule(block);
  }
  if(rule == 'origin'){
    result = originRule(block);
  }
  if(rule == 'hfh'){
    result = hfhRule(block);
  }
  return result;
}

String? hfhRule(String block){
  int? len = int.tryParse(block.substring(4,6));
  if(len != null && block.length>len+6){
    var no = block.substring(6,len+6);
    return no;
  }
  return null;
}

String? originRule(String block){
  if(block.length > 2){
    return block.substring(0,block.length-2);
  }
  return null;
}

String? xyRule(String block){
  int? len = int.tryParse(block.substring(0,2));
  if(len != null && block.length>len+2){
    var no = block.substring(2,len+2);
    return no;
  }
  return null;
}

String? ntRule(String block){
  int index = block.indexOf('FF5208');
  if(index != -1){
    String data = block.substring(0,index);
    return hexToAscii(data);
  }
  return null;
}


